<?php
/**
 * @version        $Id$
 * @author         master@xuewl.com
 * @copyright      Copyright (c) 2007 - 2014, Chongqing xuewl Information Technology Co., Ltd.
 * @link           http://www.xuewl.com
**/
class captcha { 
    function __construct() {
        // $this->categorys = getcache('category', 'commons');
        // $this->models = getcache('model', 'commons');
        $this->db = D('DamaLog');
        $this->account_db = D('DamaAccount');
        $this->member_db = D('Member');
        $this->setting = getcache('setting', 'member');
    }

    public function count($data = array()) {
        
    }

    /* 打码排名 */
    public function hits($data = array()) {
        $u_coin = (int) $this->setting['u_coin'];
        
        $page = max(1, (int) I('page'));
        $sqlmap = array();
        switch ($data['time']) {
            case 'today':
                $sqlmap['_string'] = "DATE_FORMAT(FROM_UNIXTIME(inputtime),'%Y%m%d') = DATE_FORMAT(NOW(),'%Y%m%d')";
                break;
            case 'yesterday':
                $sqlmap['_string'] = "TO_DAYS(NOW()) - TO_DAYS(FROM_UNIXTIME(inputtime)) = 1;";
                break;
            default:
                # code...
                break;
        }
        $lists = $this->db->field("*,SUM(yard_u_coin) AS top_yard_u_coin")->where($sqlmap)->page($page, $data['limit'])->order("top_yard_u_coin DESC")->group('uid')->select();
        $result = array();
        $n = ($page - 1) * $data['limit'];
        foreach ($lists as $key => $value) {
            $n++;
            $value['rmb'] = round($value['top_yard_u_coin'] / $u_coin);
            $value['nickname'] = $this->member_db->getFieldByUserid($value['uid'], 'nickname');
            $result[$n] = $value;
        }
        return $result;
    }
}